package com.yufu.baidu.ocr;

import com.baidu.ocr.sdk.model.IDCardResult;
import com.baidu.ocr.sdk.model.Word;
import com.getcapacitor.JSObject;

import org.json.JSONException;

public class IDCardResultJSObject {
  private final IDCardResult original;
  private final int direction;
  private final int wordsResultNumber;
  private final Word address;
  private final Word idNumber;
  private final Word birthday;
  private final Word name;
  private final Word gender;
  private final Word ethnic;
  private final String idCardSide;
  private final String riskType;
  private final String imageStatus;
  private final Word signDate;
  private final Word expiryDate;
  private final Word issueAuthority;

  public IDCardResultJSObject(IDCardResult original) {
    this.original = original;
    direction = original.getDirection();
    wordsResultNumber = original.getWordsResultNumber();
    address = original.getAddress();
    idNumber = original.getIdNumber();
    birthday = original.getBirthday();
    name = original.getName();
    gender = original.getGender();
    ethnic = original.getEthnic();
    idCardSide = original.getIdCardSide();
    riskType = original.getRiskType();
    imageStatus = original.getImageStatus();
    signDate = original.getSignDate();
    expiryDate = original.getExpiryDate();
    issueAuthority = original.getIssueAuthority();
  }

  public int getDirection() {
    return direction;
  }

  public int getWordsResultNumber() {
    return wordsResultNumber;
  }

  public Word getAddress() {
    return address;
  }

  public Word getIdNumber() {
    return idNumber;
  }

  public Word getBirthday() {
    return birthday;
  }

  public Word getName() {
    return name;
  }

  public Word getGender() {
    return gender;
  }

  public Word getEthnic() {
    return ethnic;
  }

  public String getIdCardSide() {
    return idCardSide;
  }

  public String getRiskType() {
    return riskType;
  }

  public String getImageStatus() {
    return imageStatus;
  }

  public Word getSignDate() {
    return signDate;
  }

  public Word getExpiryDate() {
    return expiryDate;
  }

  public Word getIssueAuthority() {
    return issueAuthority;
  }

  public IDCardResult getOriginal() {
    return original;
  }

  public JSObject getJSObject() {
    JSObject data = new JSObject();
    data.put("address", this.address);
    data.put("idNumber", this.idNumber);
    data.put("birthday", this.birthday);
    data.put("name", this.name);
    data.put("gender", this.gender);
    data.put("ethnic", this.ethnic);
    data.put("signDate", this.signDate);
    data.put("expiryDate", this.expiryDate);
    data.put("issueAuthority", this.issueAuthority);
    try {
      JSObject original = new JSObject(this.original.getJsonRes());
      data.put("original", original);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return data;
  }

}
